<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>        

<script type="text/javascript">	
	$(document).ready(function(){
		//초기에 화면에 뿌려줄 내용
		$.ajax({
			type:"POST",
			url:"hopeSubjectList.do",
			dataType:"json",
			success:function(jsonData){	
 				//희망과목 가져와서 뿌리기
				$("#subject_hopesubject option").remove();
				op="<option value='false'>--</option>";
				$("#subject_hopesubject").append(op);
 				$.each(jsonData.hopeSubjectList,function(index,hopesubjectlist){
 					op="<option value="+hopesubjectlist.code_code+">"+hopesubjectlist.code_name+"</option>";
					$("#subject_hopesubject").append(op); 
				});
			}//success
		});//ajax
		
		$("#searchForm").submit(function(){
			var subject_hopesubject=$("#subject_hopesubject").val();
			var name=$("#name").val();
			if(subject_hopesubject=="false" && name==""){
				alert("검색조건 선택없이 검색하시겠습니까?.");
			}else{	//조건에 따른 검색
				$.ajax({
					type:"POST",
					url:"getSearchStudentList.do",
					data:$("#searchForm").serialize(),
					dataType:"json",
					success:function(jsonData){
						alert("검색조건 성공!!");
					}
				});				
			}
			//confirm("전송하시겠습니까?"); 에서 확인을 누르면 전송한다.
			
			//추가 테스트 : name 로 접근하기 위해서는 jquery selector 를 활용
			// alert($("#userAddress").val()); // 정상작동 안됨
			//return confirm("sido : "+sido+"gugun : "+gugun+"name : "+name+"grade : "+grade+"gender : "+gender+", subject_hopesubject : "+subject_hopesubject+" 검색하시겠습니까?"); 
			//return false; //return false 는 object의 진행을 멈추게 한다.
		});
		
		
	});
</script>

<form id=searchForm action="searchStudentList.do">
<table width="560"  cellpadding="2" cellspacing="0"><tr><td>
	<table  >
		<tr>
			<td>희망과목</td><td><select id="subject_hopesubject"></select></td>	
			<td align="right"><input type="submit"  value="검색"> </td>
			<td>이름</td><td><input type="text" id="name"></td>
		</tr>
	</table>
</td></tr></table>	
</form>
<table width="560" cellpadding="2" cellspacing="0"><tr align="right"><td>
총 학생 수 : ${requestScope.listVO.pagingBean.totalContent}
</td></tr></table>	
<table width="560"  border="1" cellpadding="2" cellspacing="0">
	<thead>
		<tr><td width="20%">이름</td>
			 <td width="20%">성별</td>
			 <td width="20%">희망지역</td>
			 <td width="20%">희망과목</td>
			 <td width="20%">학교</td>
		</tr>
	</thead>
	<tbody>
			<c:forEach var="mvo" items="${requestScope.listVO.list}">		
			<tr>
			    <td><a href="showContent.do?id=${mvo.id }" target="_blank">${mvo.name }</a></td>			
				<td>${mvo.gender}</td>
				<td>${mvo.hoperegion}</td>
				<td>${mvo.hopesubject}</td>
				<td>${mvo.id}</td>
			</tr>
			</c:forEach>	
	</tbody>	
</table><br>
<table width="560"  cellpadding="2" cellspacing="0"><tr align="center"><td>
<c:set var="pb" value="${requestScope.listVO.pagingBean}"></c:set>
<c:if test="${pb.previousPageGroup}">
	<a href="tabSubjectView.do?pageNo=${pb.startPageOfPageGroup-1 }">	Pre </a>
</c:if>	

<c:forEach var="pageNo" begin="${pb.startPageOfPageGroup }" 
										end="${pb.endPageOfPageGroup }">
<c:choose>
<c:when test="${pb.nowPage !=pageNo }" >
	<a href="tabSubjectView.do?pageNo=${pageNo }" >${pageNo }</a>
</c:when>
<c:otherwise>
	${pageNo} 
</c:otherwise>
</c:choose>
</c:forEach>

<c:if test="${pb.nextPageGroup}">
	<a href="tabSubjectView.do?pageNo=${pb.endPageOfPageGroup+1 }">Next </a>
</c:if>
</td></tr></table>	
<br>


